package com.kye.express.business.waybill_take_photo.yunmai;

import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;

import com.yunmai.cc.smart.eye.controler.OcrManager;
import com.yunmai.cc.smart.eye.util.UtilApp;
import com.yunmai.cc.smart.eye.vo.ResultInfo;

/**
 * 识别线程
 * @author fangcm 2012-09-03
 *
 */
public class RecognitionThread extends Thread implements Runnable{

	private Handler mHandler ;
	private Rect rect;
	private OcrManager ocrManager;
	private boolean isPhoto;
	private byte[] data = null;
	private boolean isBlurOn = true;//模糊判断是否打开
	private String imgPath;

	/**
	 * @param handler
	 * @param data 图片数据
	 * @param ocrManager
	 * @param rect 绿框范围
	 * @param isPhoto 是否为JPG图片(拍照图片)
	 * @param isBlurOn 模糊判断是否打开
	 * @param imgPath 图片保存路径   注意:请确保路径所在文件夹已经存在  且文件后缀名需为  .bmp
	 *
	 */
	public RecognitionThread(Handler handler, byte[] data , OcrManager ocrManager, Rect rect, boolean isPhoto,
							 boolean isBlurOn, String imgPath){
		this.mHandler = handler;
		this.data = data;
		this.ocrManager = ocrManager;
		this.rect = rect;
		this.isPhoto = isPhoto;
		this.isBlurOn = isBlurOn;
		this.imgPath = imgPath;
	}


	@Override
	public void run() {
		// TODO Auto-generated method stub
		Message msg = mHandler.obtainMessage();
		//后面三个参数  （第一个 1至15数字识别运单的区域）（第二个  0:做美化  1:不做美化   2：图片变黑白） （第三个  是否需要判断付款方式  0判断，1不判断）
		ResultInfo resultInfo = ocrManager.recognitionPhoto(data ,rect,mHandler,isPhoto,isBlurOn,imgPath,   1,1,1);
		if(resultInfo != null){
			msg.what = UtilApp.RECOGN_OK;
			msg.obj = resultInfo;
			mHandler.sendMessage(msg);
		}else{
			if(isPhoto){
				mHandler.sendEmptyMessageDelayed(UtilApp.CAMERA_TAKE_PHOTO_ERROR,100);
			}else{
				msg.what = UtilApp.RECOGN_FAIL;
				mHandler.sendMessage(msg);
			}
		}
	}



}
